﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame1
{
    class Nave
    {
        Texture2D textura;
        Rectangle recTextura;
        Rectangle recColisao;
        
        const int largura = 35;
        const int altura = 43;
        GameWindow gameWindow;
        GerenciadorTiro gerenciadorTiro;

        public Rectangle RecColisao
        {
            get
            {
                return recColisao;
            }
        }

        public Nave(ContentManager Content, Texture2D textura, GameWindow gw)
        {
            this.textura = textura;
            this.gameWindow = gw;
            ColocandoNaPosicaoInicial();
            recTextura = new Rectangle(0, 0, largura, altura);
            gerenciadorTiro = new GerenciadorTiro(Content,Content.Load<Texture2D>("tiro"), gw);
            
        }

        public void ColocandoNaPosicaoInicial()
        {
            recColisao.X = gameWindow.ClientBounds.Width / 2;
            recColisao.Y = gameWindow.ClientBounds.Height - altura;
            recColisao.Width = largura;
            recColisao.Height = altura;
        }

        public void Update(GameTime gameTime, KeyboardState tecladoAtual, KeyboardState tecladoAnterior, GamePadState gamePadAtual, GamePadState gamePadAnterior)
        {
           
            recColisao.X += (int)(gamePadAtual.ThumbSticks.Left.X * 5);
            recColisao.Y += -(int)(gamePadAtual.ThumbSticks.Left.Y * 5);
            

            if (recColisao.X >= gameWindow.ClientBounds.Width - largura)
            {
                recColisao.X = gameWindow.ClientBounds.Width - largura;
            }
            if (recColisao.X <= 0)
            {
                recColisao.X = 0;
            }

            if (recColisao.Y <= 0)
            {
                recColisao.Y = 0;
            }
            if (recColisao.Y >= gameWindow.ClientBounds.Height - altura)
            {
                recColisao.Y = gameWindow.ClientBounds.Height - altura;
            }

            if (tecladoAtual.IsKeyDown(Keys.Left))
            {
                recColisao.X-=10;
            }

            if (tecladoAtual.IsKeyDown(Keys.Right))
            {
                recColisao.X+=10;
            }
              
            gerenciadorTiro.Update(gameTime, new Vector2((int)recColisao.X + largura/2, (int)recColisao.Y));
                           
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(textura, recColisao, Color.White);
            gerenciadorTiro.Draw(gameTime, spriteBatch);
          
        }

    }
}
